﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.Common;

namespace NUnitForVSTS.NUnitTest
{
    /// <summary>
    /// Creates MS Test Results
    /// </summary>
    static class ResultFactory
    {
        /// <summary>
        /// Creates the error.
        /// </summary>
        /// <param name="nunitTest">The nunit test.</param>
        /// <param name="e">The exception</param>
        /// <param name="testRunId">The test run id.</param>
        /// <returns></returns>
        public static UnitTestResult CreateErrorResult(UnitTest nunitTest, Exception e, Guid testRunId)
        {
            UnitTestResult error = CreateErrorResult(nunitTest, e.Message, testRunId);
            error.ErrorInfo = new TestResultErrorInfo(e.Message);
            error.ErrorStackTrace = e.StackTrace;
            error.ErrorMessage = e.Message;
            return error;
        }

        /// <summary>
        /// Creates the error.
        /// </summary>
        /// <param name="nunitTest">The nunit test.</param>
        /// <param name="message">The message.</param>
        /// <param name="testRunId">The test run id.</param>
        /// <returns></returns>
        public static UnitTestResult CreateErrorResult(UnitTest nunitTest, string message, Guid testRunId)
        {
            UnitTestResult error = CreateResult(nunitTest, testRunId);
            error.Outcome = TestOutcome.Error;
            error.ErrorMessage = message;
            return error;
        }

        /// <summary>
        /// Creates the result.
        /// </summary>
        /// <param name="test">The test.</param>
        /// <param name="testRunId">The test run id.</param>
        /// <returns></returns>
        public static UnitTestResult CreateResult(ITestElement test, Guid testRunId)
        {
            return new UnitTestResult(Environment.MachineName, testRunId, test);
        }
    }
}
